window.requestAnimFrame = (function() {
	return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame ||
	function( /* function FrameRequestCallback */ callback, /* DOMElement Element */ element) {
		return window.setTimeout(callback, 1000 / 60);
	};
})();


function getRanAng() {
	return Math.random() * Math.PI * 2;
}

function calLength(x1, y1, x2, y2) {
	return Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2);
}

function randomColor() {
	var col = [0, 1, 2];
	col[0] = Math.random() * 100 + 155;
	col[0] = col[0].toFixed();
	col[1] = Math.random() * 100 + 155;
	col[1] = col[1].toFixed();
	col[2] = Math.random() * 100 + 155;
	col[2] = col[2].toFixed();
	var num = Math.floor(Math.random() * 3);
	col[num] = 0;
	return "rgba(" + col[0] + "," + col[1] + "," + col[2] + ",";
}

function drawCircle(x, y, r) {
	var alpha = 0;
	ctx.moveTo(x + r, y);
	for (var i = 0; i < 60; i++) {
		alpha += 12 * Math.PI / 180;
		ctx.lineTo(x + r * Math.cos(alpha), y + r * Math.sin(alpha));
	}
	if (alpha > Math.PI * 2) {
		alpha = 0;
	}

	ctx.strokeStyle = "#ffffff";
	ctx.stroke();
}

function getAngle(x, y) {
	var r = Math.sqrt(x * x + y * y);
	var theta = Math.acos(x / r);
	if (y < 0) theta += Math.PI;
	return theta;
}

function lerpAngle(a, b, t) {
	var d = b - a;
	if (d > Math.PI) d = d - 2 * Math.PI;
	if (d < -Math.PI) d = d + 2 * Math.PI;
	return a + d * t;
}

function inOboundary(arrX, arrY, l, r, t, b) { //在l r t b范围内的检测
	return arrX > l && arrX < r && arrY > t && arrY < b;
}

function inHboundary(arrX, arrY, l, r) { //在l r t b范围内的检测
	return arrX > l && arrX < r;
}

function inJellyBody(fx, fy, jx, jy) {
	return fx > jx + 10 && fx < jx + 60 && fy > jy + 50 && fy < jy + 170;
}

function rgbColor(r, g, b) {
	r = Math.round(r * 256);
	g = Math.round(g * 256);
	b = Math.round(b * 256);
	return "rgba(" + r + "," + g + "," + b + ",1)"
}

function rnd(m)
{
	var n = m || 1;
	return Math.random()*n;
}